﻿using CefSharp;
using CefSharp.WinForms;
using FictionsDownload.BLL;
using FictionsDownload.BLL.CefSharp;
using FictionsDownload.Enums;
using FictionsDownload.Events;
using Zzw;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FictionsDownload.UI
{
    public partial class FormCefSharp : Form
    {
        #region 单例初始化
        private FormCefSharp(ICefSharp cefSharp)
        {
            webBrowser = cefSharp;
            InitializeComponent();
            this.TopLevel = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.Show();
        }
        private static FormCefSharp formInstance { get; set; }
        private static readonly object lockRoot = new object();
        /// <summary>
        /// 初始化实例
        /// </summary>
        public static FormCefSharp GetIntance(ICefSharp cefSharp)
        {
            if (formInstance == null)
            {
                lock (lockRoot)
                {
                    if (formInstance == null)
                    {
                        formInstance = new FormCefSharp(cefSharp);
                    }
                }
            }
            return formInstance;
        }
        #endregion
        #region 内部变量和属性
        /// <summary>
        /// 浏览器对象
        /// </summary>
        public ICefSharp webBrowser { get; set; }
        #endregion
        #region 公众属性和事件
        /// <summary>
        /// 父窗口对象（后续重构成事件）
        /// </summary>
        private FormQidian FormQidian
        {
            get
            {
                if (this.MdiParent == null)
                {
                    //父窗体不是FormMain，是Panel
                    return (FormQidian)this.Parent.Parent;
                }
                else
                {
                    return (FormQidian)this.MdiParent;
                }
            }
        }
        #endregion
        public void InitializeComponentCode()
        {
            web_Auto_Init();
        }
        public void web_Auto_Init()
        {
            this.Controls.Add(webBrowser.WebBrowser);
            //web_Auto布局
            webBrowser.WebBrowser.Dock = DockStyle.None;
            webBrowser.WebBrowser.Location = new Point(0, 0);
            webBrowser.WebBrowser.Size = this.Size;
            this.webBrowser.WebBrowser.Anchor = (((AnchorStyles.Top | AnchorStyles.Bottom)| AnchorStyles.Left)| AnchorStyles.Right);
        }
    }
}
